<?php
	include("_session.php");
	include("_findmsl.php");	
if(count($_GET)>0)
{
	$dist = $_GET["dist"];
	$mslno = $_GET["mslno"];
	$chkdgt = $_GET["chkdgt"];
	$ordcamp = $_GET["ordcamp"];
		
	$order_date = date('d/m/Y H:i:s');	
	$order_no = getOrderNo($conn, $dist, $mslno, $chkdgt, $ordcamp);
	$memberno = mergeMsl($dist, $mslno, $chkdgt);
	$mslname = findMsl($conn, $dist, $mslno, $chkdgt);
	$maxCamp = getMaxCamp($conn);
	$minCamp = getMinCamp($conn);
	if (!isset($_SESSION['ORDER_DETAIL'])) $_SESSION['ORDER_DETAIL'] = array();
}
else
{
	header("Location:quickorder.php");
}
//print_r($_SESSION['ORDER_DETAIL']);
?>
<!DOCTYPE html>
<html lang="th" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
	<META HTTP-EQUIV="EXPIRES" CONTENT="Mon, 22 Jul 2002 11:12:01 GMT">
    <META HTTP-EQUIV="Pragma" CONTENT="no-cache">  
    <title>TOS-New order</title>
    <link href="css/default.css?v=<?php echo date("YmdHis"); ?>" rel="stylesheet" type="text/css" >
    <script src="js/jquery-1.7.1.js?v=<?php echo date("YmdHis"); ?>" type="text/javascript"></script>
    <script src="js/jquery-ui-1.8.20-core.js?v=<?php echo date("YmdHis"); ?>" type="text/javascript"></script>
    <script src="js/form.js?v=<?php echo date("YmdHis"); ?>" type="text/javascript"></script>	 
	<link href="css/flexigrid.css?v=<?php echo date("YmdHis"); ?>" rel="stylesheet" type="text/css" media="all" />
	<script src="js/flexigrid.js?v=<?php echo date("YmdHis"); ?>" type="text/javascript"></script>
</head>
<body>
<?php include("_header.php"); ?>
<form action="_savenew.php" method="POST" id="main-form">
	<table>
        <tr>
            <td><?php echo $l_orderdate; ?></td>
            <td>
                <input type="text" id="ORDDATE" name="ORDDATE" 
                class="readonly" readonly="true"
                value="<?php echo $order_date; ?>" /></td>
            <td><?php echo $l_orderno; ?></td>
            <td>
                <input 
                	type="text" id="ORDNO" name="ORDNO" 
                	class="readonly" readonly="true" 
                	value="<?php echo $order_no; ?>" /></td>
        </tr>
        <tr>
            <td><?php echo $l_mslno; ?></td>
            <td>
                <input 
                	type="text" id="MEMBERNO" name="MEMBERNO" 
                	class="readonly" readonly="true" 
                	value="<?php echo $memberno; ?>" /></td>
            <td><?php echo $l_campaign; ?></td>
            <td>
                <select id="ORDCAMP" name="ORDCAMP" class="dropdown">
                <?php
                	$sql = "SELECT * FROM tbl008 order by camp";
                	$raw = mysql_query($sql, $conn);                	
                	while ($row = mysql_fetch_array($raw, MYSQL_ASSOC))
                	{                											
                ?>
                    <option 
                    	value="<?php echo $row["CAMP"]; ?>"
                    	<?php 
                    		if ($ordcamp == $row["CAMP"]) echo "selected=\"true\""; 
                    	?>>
                    	<?php echo displayCamp($row["CAMP"]); ?>                    		
                    </option>
                <?php
                	}    
                ?>
                </select></td>
        </tr>
        <tr>
            <td><?php echo $l_membername; ?></td>
            <td colspan="3">
                <input type="text" id="MSLNAME" name="MSLNAME" 
                class="readonly" readonly="true" size="30"
                value="<?php echo $mslname; ?>"/></td>
        </tr>
    </table>
	<hr />
	<table>
		<tr>
			<td>
				<table>
					<tr>
						<td><?php echo $l_billcode; ?></td>
						<td><input 
			                	type="text" class="textbox" 
			                	id="BILLCODE" 
			                	name="BILLCODE" 
			                	maxlength="5" size="5"
			                	onkeydown="return validateNumber(event, this);" /></td>
						<td><?php echo $l_qty; ?></td>
						<td><input 
			                	type="text" class="textbox" 
			                	id="QTY" 
			                	name="QTY" 
			                	maxlength="4" size="4" 
			                	onkeydown="return validateNumber(event, this);" /></td>
						<td><?php echo $l_price; ?></td>
						<td><input 
			                	type="text" 
			                	id="PRICE" 
			                	name="PRICE" 
			                	size="6" class="readonly" 
			                	readonly="true" /></td>
						<td><?php echo $l_amount; ?></td>
						<td><input 
			                	type="text" 
			                	id="AMOUNT" 
			                	name="AMOUNT" 
			                	size="10" class="readonly" 
			                	readonly="true" />
			                <input 
			                	type="hidden" 
			                	id="ORDCAMPD" name="ORDCAMPD" />
			            </td>                            	
					</tr>
					<tr>
			<td><?php echo $l_billdesc; ?></td>
			<td colspan="7"><textarea 
                	id="BILLDESC" 
                	name="BILLDESC" 
                	cols="70" rows="2" 
                	readonly="true" 
                	class="readonly">                	
                </textarea></td>
		</tr>					
				</table>
			</td>
			<td>
				<fieldset>
					<legend>Summary:</legend>
					<table>
						<tr>
							<td><?php echo $l_items; ?></td>
							<td><input type="text" 
				                	id="ITEMS" 
				                	name="ITEMS" 
				                	size="10" class="readonly" 
			                		readonly="true" /> ชิ้น</td>						
							<td><?php echo $l_total; ?></td>
							<td><input type="text" 
				                	id="TOTAL" 
				                	name="TOTAL" 
				                	size="12" class="readonly" 
			                		readonly="true" /> บาท</td>
						</tr>
						<tr>
							<td><?php echo $l_list; ?></td>
							<td><input type="text" 
				                	id="LIST" 
				                	name="LIST" 
				                	size="10" class="readonly" 
			                		readonly="true" /> รายการ</td>
							<td colspan="2" align="center">
								<input type="button" 
                					value="คำนวณใหม่" id="Calculate" 
                					class="button" /></td>
						</tr>												
					</table>
				</fieldset>
			</td>
		</tr>
	</table>             	
	<table class="flexme4" style="display: none"></table>
	<table>
        <tr>
            <td>
                <input type="button" 
                	value="ลบรายการทั้งหมด" id="DeleteAll_B" 
                	class="button" />
                <input type="button" 
                	value="บันทึกการสั่งซื้อ" id="Save_B" 
                	class="button" />
                <input type="hidden" name="DIST" value="<?php echo $dist; ?>"/>                
                <input type="hidden" name="MSLNO" value="<?php echo $mslno; ?>"/>  
                <input type="hidden" name="CHKDGT" value="<?php echo $chkdgt; ?>"/>
                <input type="hidden" id="MAXCAMP" value="<?php echo $maxCamp; ?>"/>
                <input type="hidden" id="MINCAMP" value="<?php echo $minCamp; ?>"/>                
            </td>
        </tr>
    </table>
</form>	   
<script type="text/javascript">
	$(document).ready(function () { 
        $("#BILLCODE").focus();
        $("#BILLDESC").val("");
	    getSummary();        
	    $("#ORDCAMP").change(function () {
	        if (confirm('<?php echo $Warning; ?>')) {
	            $("#main-form").attr("action", '_getorder.php');
	            $("#main-form").submit();            
	        }
	        else {
	            $("#ORDCAMP").val('<?php echo $ordcamp; ?>');
	        }
	    });
	        
	    $("input[id*='DeleteAll_']").click(function () {
	        if (!confirm('<?php echo $ConfirmDeletes; ?>'))
	            event.preventDefault ? event.preventDefault() : event.returnValue = false;
	        else {
	            $("#main-form").attr("action", "quickorder.php");
	            $("#main-form").submit();
	        }
	    });
	    
	    $("#Save_B").click(function () {
	    	getSummary();	 	    	
	    	getCount();   	
	    });
	    
		$('#Calculate').click(function() {
	    	getSummary();	 	    	
			location.reload();
		});	    	    
	    
        $(".flexme4").flexigrid({
            url : '_getorderDetail.php',
            dataType : 'json',
            colModel : [{
	                display : '<?php echo $l_listno; ?>',
	                name : 'LISTNO',
	                width : 50,
	                sortable : false,
	                align : 'center'
                }, {
                    display : '<?php echo $l_billcode; ?>',
                    name : 'BILLCODE',
                    width : 100,
                    sortable : false,
                    align : 'left'
                }, {
                    display : '<?php echo $l_billdesc; ?>',
                    name : 'BILLDESC',
                    width : 500,
                    sortable : false,
                    align : 'left'
                }, {
                    display : '<?php echo $l_qty; ?>',
                    name : 'QTY',
                    width : 50,
                    sortable : false,
                    align : 'right'
                }, {
                    display : '<?php echo $l_price; ?>',
                    name : 'PRICE',
                    width : 100,
                    sortable : false,
                    align : 'right'
            	}, {
                    display : '<?php echo $l_amount; ?>',
                    name : 'AMOUNT',
                    width : 100,
                    sortable : false,
                    align : 'right'
            	}],
            buttons : [{
                    name : 'Delete',
                    bclass : 'delete',
                    onpress : doCommand
                }, {
                    separator : true
                }],
            usepager : false,
            title : '<?php echo $l_detail; ?>',
            width : 999,
            height : 200,
            showTableToggleBtn : false,
            nowrap : false,
            resizable : false,
            sortname : "LISTNO",
            sortorder : "desc"       
        }); 
        
		$("#BILLCODE").focusin(function() {
			$("#BILLCODE").val("");
			$("#BILLDESC").val("");
			$("#PRICE").val("");
		});
		
		getResponseTime();         
	});
</script>
</body>
</html>
<?php
	include("_close.php");
?>